package fibonacci;

import java.util.Arrays;

public class Way4 {
	
	public static void main(String[] args) {
		final int num = 20;
		Way4 way4 = new Way4();
		//结果为：6765，一共执行了19次
		System.out.println("结果为："+way4.fab(num)+"，一共执行了"+way4.count+"次");
	}
	
	private int count = 0;
	
	public int fab(int num) {
		if(num<=0) {
			count++;
			return 0;
		}
		if(num==1) {
			count++;
			return 1;
		}
		int[] array = new int[num+1];
		array[0] = 0;
		array[1] = 1;
		for(int i=2;i<=num;i++) {
			count++;
			array[i] = array[i-1] + array[i-2];
		}
		System.out.println(Arrays.toString(array));
		return array[num];
	}

}
